package com.zhz.livegoods.search.service.impl;

import com.zhz.livegoods.commons.vo.LivegoodsResult;
import com.zhz.livegoods.search.dao.ItemDao4ES;
import com.zhz.livegoods.search.pojo.Item4ES;
import com.zhz.livegoods.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.stereotype.Service;

/**
 * 搜索服务实现
 * @author zhz
 * @date 2020/08/05
 **/
@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private ItemDao4ES itemDao4ES;
    /**
     * 搜索商品
     * @param city 城市
     * @param content 搜索关键字
     * @param page 第几页， 从0开始
     * @param rows 每页查询多少行
     * @return
     */
    @Override
    public LivegoodsResult search(String city, String content, int page, int rows) {

        // 搜索商品
        AggregatedPage<Item4ES> resultPage = itemDao4ES.query4Page(city, content, page, rows);
        //返回结果
        LivegoodsResult result=LivegoodsResult.ok(resultPage.getContent());
        if (page<(resultPage.getTotalPages()-1)){// 查询的当前页码小于总计页码
            result.setHasMore(true);
        }else {
            result.setHasMore(false);
        }

        return result;
    }
}
